//
//  BaseViewController.m
//  安好
//
//  Created by 冯凯 on 14-10-27.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "BaseViewController.h"
#import "LoginViewController.h"
#import "TencentOpenAPI/QQApiInterface.h"
#import "WeiboSDK.h"
#import "AppDelegate.h"
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import "iflyMSC/IFlyRecognizerView.h"
#import "iflyMSC/IFlyRecognizerViewDelegate.h"
#define APPID @"5313e44f"
#import "SystemMessageCenter.h"

@interface BaseViewController ()<MFMessageComposeViewControllerDelegate,IFlyRecognizerViewDelegate
>
{
    UIView *hiddenView;
    IFlyRecognizerView      * _iflyRecognizerView;

}
@end

@implementation BaseViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    
    [self viewWithBaseView];
    
    self.view.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    
    /**
     *  防止下滑
     */
    self.automaticallyAdjustsScrollViewInsets = NO;
    /**
     *  BaseDelegate的代理
     */
    self.baseRequestDelegate = self;
    
    [self actionView];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    [self baseShareView];
    [self voiceView];
    [self baseViewAddLoadingView];
    
    
}

- (void)viewWithBaseView
{
    self.baseLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth/2-200/2, kScreenHeight/2+20, 200, 20)];
    self.baseLabel.hidden = YES;
    self.baseLabel.textAlignment = 1;
    self.baseLabel.font = [UIFont systemFontOfSize:13];
    self.baseLabel.textColor = [UIColor lightGrayColor];
    [self.navigationController.view.superview addSubview:self.baseLabel];
}
- (void)shouLabel: (NSString *)labelText
{
    self.baseLabel.hidden = NO;
    self.baseLabel.text = labelText;
}
- (void)hiddenLabel
{
    self.baseLabel.hidden = YES;
}
- (void)viewWillAppear:(BOOL)animated{
    [[SystemMessageCenter instance] loadDataForIsFirstResign:NO];

    [super viewWillAppear:animated];

}
- (void)viewWillDisappear:(BOOL)animated
{    [self hiddenLabel];
    [self hiddenActionView];
}
- (void)voiceView
{
    NSString *initString = [NSString stringWithFormat:@"appid=%@",APPID];
    _iflyRecognizerView = [[IFlyRecognizerView alloc] initWithCenter:CGPointMake(kScreenWidth/2, kScreenHeight/2) initParam:initString];
    _iflyRecognizerView.delegate = self;
    [_iflyRecognizerView setParameter:@"domain" value:@"iat"];
    [_iflyRecognizerView setParameter:@"asr_audio_path" value:@"asrview.pcm"];
    
}
- (void)starVoice
{
    [_iflyRecognizerView start];
}
- (void)cancelVoice
{
    [_iflyRecognizerView cancel];
}
#pragma mark delegate    科大讯飞的代理
- (void)onResult:(IFlyRecognizerView *)iFlyRecognizerView theResult:(NSArray *)resultArray
{
    NSMutableString *result = [[NSMutableString alloc] init];
    NSDictionary *dic = [resultArray objectAtIndex:0];
    for (NSString *key in dic) {
        [result appendFormat:@"%@",key];
    }
    self.voiceString = [NSString stringWithFormat:@"%@",result];
    if ([self.voiceString isEqualToString:@"."] || [self.voiceString isEqualToString:@"。"] || [self.voiceString isEqualToString:@"?"] || [self.voiceString isEqualToString:@"？"] || [self.voiceString isEqualToString:@"!"] || [self.voiceString isEqualToString:@"！"]){
        
    }else{
    if ([self.baseRequestDelegate respondsToSelector:@selector(voice:)]) {
        [self.baseRequestDelegate voice:self.voiceString];
        [self cancelVoice];
    }
    }
}

- (void)onEnd:(IFlyRecognizerView *)iFlyRecognizerView theError:(IFlySpeechError *)error
{
    //    //NSLog(@"errorCode:%d",[error errorCode]);
}

#pragma - mark 加载中
/**
 *  加载中
 */
- (void)actionView
{
//    self.mbPro = [[MBProgressHUD alloc]initWithView:self.view];
//    self.mbPro.customView.frame = CGRectZero;
//    [self.mbPro setLabelText:@"加载中"];
//    [self.navigationController.view.superview addSubview:self.mbPro];
    

}
/**
 *  显示加载中
 */
- (void)showActionView
{
//    self.mbPro.mode = MBProgressHUDModeIndeterminate;
//    self.mbPro.center=self.view.center;
//    [self.mbPro show:YES];
//    self.LoadingView.hidden = NO;
//    [self.view addSubview:self.LoadingView];
    
    
    self.LoadingView.hidden = NO;

}
/**
 *  隐藏加载中
 */
- (void)hiddenActionView
{
//    self.LoadingView.hidden = YES;
//    self.mbPro.mode = MBProgressHUDModeIndeterminate;
//    [self.mbPro hide:YES];
    
    self.LoadingView.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma - mark 判断登录
/**
 *  跳转登录
 */
- (void)isLogin
{
    NSString * userIsLogin =  [NSString stringWithFormat:@"%@",[[UserManager shareInstance] getUserIsLogin]];
    if ([userIsLogin length] == 0|| [[UserManager shareInstance]getUserIsLogin ] == nil) {

        LoginViewController * loginViewController = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
        NSUserDefaults * user =[NSUserDefaults standardUserDefaults];
        [user setObject:@"ios8" forKey:@"ios8"];
        UINavigationController * navi  =[[UINavigationController alloc]initWithRootViewController:loginViewController];
        [self presentViewController:navi animated:YES completion:^{
            }];
    }else{
        if ([self.baseRequestDelegate respondsToSelector:@selector(Login)]) {
            [self.baseRequestDelegate Login];
        }
    }
}





#pragma - mark QQ分享
/**
 *  QQ分享
 *
 *  @param shareUrl        qq分享链接
 *  @param shareTitle      qq分享标题
 *  @param shreDescription qq分享类型
 *  @param shareImageUrl   qq分享图片的链接
 */
- (void)qqShare:(NSString *)qqShareUrl :(NSString *)qqShareTitle :(NSString *)qqShareDescription :qqShareImage{
    NSString *url = qqShareUrl;
    NSString *title = qqShareTitle;
    if ([qqShareDescription length] > 150){
        self.qqShareString = [qqShareDescription substringToIndex:150];
    }else{
        self.qqShareString = qqShareDescription;
        
    }
    NSString *description = self.qqShareString;
    NSData *previewData = UIImagePNGRepresentation(qqShareImage);
    QQApiNewsObject *newsObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:description previewImageData:previewData];
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
    QQApiSendResultCode sent = [QQApiInterface sendReq:req];
    [self handleSendResult:sent];
    
}
/**
 *  QQ空间分享
 *
 *  @param qqZoneShareUrl         qq空间分享的链接
 *  @param qqZoneShareTitle       qq空间分享的标题
 *  @param qqZoneShareDescription qq空间分享的类型
 *  @param qqZoneShareImageUrl    qq空间分享图片的链接
 */
- (void)qqZoneShare:(NSString *)qqZoneShareUrl :(NSString *)qqZoneShareTitle :(NSString *)qqZoneShareDescription :(UIImage *)qqZoneShareImage{
    NSString *url = qqZoneShareUrl;
    NSString *title = qqZoneShareTitle;
//    NSString *description = qqZoneShareDescription;
    if ([qqZoneShareDescription length] > 150){
        self.qqShareString = [qqZoneShareDescription substringToIndex:150];
    }else{
        self.qqShareString = qqZoneShareDescription;
        
    }
    NSData *previewData = UIImagePNGRepresentation(qqZoneShareImage);
    QQApiNewsObject *newsObj = [QQApiNewsObject objectWithURL:[NSURL URLWithString:url] title:title description:self.qqShareString previewImageData:previewData];
    
    SendMessageToQQReq *req = [SendMessageToQQReq reqWithContent:newsObj];
    QQApiSendResultCode sent = [QQApiInterface SendReqToQZone:req];
    [self handleSendResult:sent];
    
}
- (void)handleSendResult:(QQApiSendResultCode)sendResult
{
    switch (sendResult)
    {
        case EQQAPISENDSUCESS:
        {
            [[NSNotificationCenter defaultCenter]postNotificationName:@"QQ" object:self userInfo:nil];
            break;
        }
        case EQQAPIAPPNOTREGISTED:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"App未注册" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"App未注册" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            break;
        }
        case EQQAPIMESSAGECONTENTINVALID:
        case EQQAPIMESSAGECONTENTNULL:
        case EQQAPIMESSAGETYPEINVALID:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"发送参数错误" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送参数错误" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            break;
        }
        case EQQAPIQQNOTINSTALLED:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"未安装手QQ" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"未安装手QQ" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            
            break;
        }
        case EQQAPIQQNOTSUPPORTAPI:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"API接口不支持" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"API接口不支持" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            
            break;
        }
        case EQQAPISENDFAILD:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"发送失败" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"发送失败" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            
            break;
        }
        case EQQAPIQZONENOTSUPPORTTEXT:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"空间分享不支持纯文本分享，请使用图文分享" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"空间分享不支持纯文本分享，请使用图文分享" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            
            break;
        }
        case EQQAPIQZONENOTSUPPORTIMAGE:
        {
            if (IOS8_OR_LATER) {
                UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"Error" message:@"空间分享不支持纯图片分享，请使用图文分享" preferredStyle:UIAlertControllerStyleAlert];
                [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                    MyNSLog("取消");
                }]];
                
                [self presentViewController:confirmAlertView animated:YES completion:^{
                    
                }];
            } else {
                UIAlertView *msgbox = [[UIAlertView alloc] initWithTitle:@"Error" message:@"空间分享不支持纯图片分享，请使用图文分享" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:nil];
                [msgbox show];
            }
            
            break;
        }
        default:
        {
            break;
        }
    }
}
#pragma - mark 微信分享
/**
 *  微信分享
 *
 *  @param weixinShareUrl      微信分享的链接
 *  @param weixinShareTitle    微信分享的标题
 *  @param weixinShareText     微信分享的内容
 *  @param weixinShareImageUrl 微信分享的图片
 */
- (void)weixinShare:(NSString *)weixinShareUrl :(NSString *)weixinShareTitle :(NSString *)weixinShareText :(UIImage *)weixinShareImage{
    

    
    
    //是否安装微信
    if (![WXApi isWXAppInstalled]) {
        if (IOS8_OR_LATER) {
            UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"错误" message:@"您还没有安装微信或者您的版本不支持分享功能!" preferredStyle:UIAlertControllerStyleAlert];
            [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                MyNSLog("确定");
            }]];
            
            [self presentViewController:confirmAlertView animated:YES completion:^{
                
            }];
        } else {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"错误" message:@"您还没有安装微信或者您的版本不支持分享功能!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
        
        return;
    }
    WXMediaMessage *message = [WXMediaMessage message];
    
    if ([weixinShareText length] > 140){
        message.description = [weixinShareText substringToIndex:140];
    }else{
        message.description = weixinShareText;
        
    }
    
//    message.description = weixinShareText ;
    
    if ([weixinShareTitle length] > 140){
        message.title = [weixinShareTitle substringToIndex:140];
    }else{
        message.title = weixinShareTitle;
        
    }
    
//    message.title = weixinShareTitle;   //长度不能超过512字节
    [message setThumbImage:weixinShareImage];
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = weixinShareUrl;
    message.mediaObject = ext;

    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneSession;
    [WXApi sendReq:req];
}
/**
 *  微信朋友圈的分享
 *
 *  @param weixinShareUrl      微信朋友圈分享的链接
 *  @param weixinShareTitle    微信朋友圈分享的标题
 *  @param weixinShareText     微信朋友圈分享的内容
 *  @param weixinShareImageUrl 微信朋友圈分享的图片
 */
- (void)weixinFriendShare:(NSString *)weixinShareUrl :(NSString *)weixinShareTitle :(NSString *)weixinShareText :(UIImage *)weixinShareImage{
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    [user setObject:@"weixin" forKey:@"weixin"];
    if (![WXApi isWXAppInstalled]) {
        
        if (IOS8_OR_LATER) {
            UIAlertController *confirmAlertView = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还没有安装微信或者您的版本不支持分享功能!" preferredStyle:UIAlertControllerStyleAlert];
            [confirmAlertView addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                MyNSLog("确定");
            }]];
            
            [self presentViewController:confirmAlertView animated:YES completion:^{
                
            }];
        } else {
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"您还没有安装微信或者您的版本不支持分享功能!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
        
        return;
    }
    WXMediaMessage *message = [WXMediaMessage message];
    if ([weixinShareText length] > 140){
        message.description = [weixinShareText substringToIndex:140];
    }else{
        message.description = weixinShareText;
        
    }
    if ([weixinShareTitle length] > 140){
        message.title = [weixinShareTitle substringToIndex:140];
    }else{
        message.title = weixinShareTitle;
        
    }
//    message.title = weixinShareTitle;
//    message.description = weixinShareText;
    [message setThumbImage:weixinShareImage];
    
    WXWebpageObject *ext = [WXWebpageObject object];
    ext.webpageUrl = weixinShareUrl;
    message.mediaObject = ext;
    SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
    req.bText = NO;
    req.message = message;
    req.scene = WXSceneTimeline;
    [WXApi sendReq:req];
}
#pragma - mark 新浪分享
/**
 *  新浪微博的分享
 *
 *  @param sinaWeiboShareUrl     新浪微博的分享的链接
 *  @param sinaWeiboShareTitle   新浪微博的分享的标题
 *  @param sinaWeiboShareText    新浪微博的分享的内容
 *  @param sinaWeiboShareImageUr 新浪微博的分享的图片
 */
- (void)sinaWeiboShare:(NSString *)sinaWeiboShareUrl :(NSString *)sinaWeiboShareTitle :(NSString *)sinaWeiboShareText :(UIImage *)sinaWeiboShareImage{
    WBMessageObject *message = [WBMessageObject message];
    if ([sinaWeiboShareText length] > 140){
        message.text = [sinaWeiboShareText substringToIndex:140];
    }else{
        message.text = sinaWeiboShareText;
        
    }
//    message.text = sinaWeiboShareText ;
    WBWebpageObject *webpage = [WBWebpageObject object];
    webpage.objectID = @"identifier1";
    
    
    if ([sinaWeiboShareTitle length] > 140){
        webpage.title = [sinaWeiboShareTitle substringToIndex:140];
    }else{
        webpage.title = sinaWeiboShareTitle;
        
    }
    if ([sinaWeiboShareText length] > 140){
        webpage.description  = [sinaWeiboShareText substringToIndex:140];
    }else{
        webpage.description  = sinaWeiboShareText;
        
    }
    
//    webpage.title = sinaWeiboShareTitle;
//    webpage.description = sinaWeiboShareText;
    webpage.thumbnailData = UIImagePNGRepresentation(sinaWeiboShareImage);
    webpage.webpageUrl = sinaWeiboShareUrl;
    message.mediaObject = webpage;
    WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
    authRequest.redirectURI = kRedirectURI;
    
    AppDelegate *myDelegate =(AppDelegate*)[[UIApplication sharedApplication] delegate];
    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:myDelegate.wbtoken];
    request.userInfo = @{@"ShareMessageFrom": @"SendMessageToWeiboViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:123],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    
    [WeiboSDK sendRequest:request];
}
#pragma - mark 短信分享
-(void)showSMSPicker:(NSString *)sinaWeiboShareUrl :(NSString *)sinaWeiboShareTitle :(NSString *)sinaWeiboShareText :(UIImage *)sinaWeiboShareImage{
    Class messageClass = (NSClassFromString(@"MFMessageComposeViewController"));
    
    if (messageClass != nil) {
        if ([messageClass canSendText]) {
            [self displaySMSComposerSheet:sinaWeiboShareUrl :sinaWeiboShareTitle :sinaWeiboShareText :sinaWeiboShareImage];
        }
        else {
            UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@""message:@"设备不支持短信功能" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
        }
    }
    else {
    }
}
/**
 *  短信分享
 */
-(void)displaySMSComposerSheet:(NSString *)sinaWeiboShareUrl :(NSString *)sinaWeiboShareTitle :(NSString *)sinaWeiboShareText :(UIImage *)sinaWeiboShareImage
{
    NSString * downUrl = sinaWeiboShareUrl;
    MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
    picker.messageComposeDelegate =self;
    NSString *smsBody =[NSString stringWithFormat:@"%@%@",sinaWeiboShareText,downUrl];
    picker.body=smsBody;
    [self presentViewController:picker animated:YES completion:^{
        
    }];
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller                   didFinishWithResult:(MessageComposeResult)result {
    switch (result){
    case MessageComposeResultCancelled:
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            break;
        case MessageComposeResultSent:
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            break;
        case MessageComposeResultFailed:
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            break;
        default:
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            break;
    }
}
#pragma - mark 分享视图
- (void)baseShareView
{
    //灰色效果，点击取消分享
    hiddenView = [[UIView alloc]initWithFrame:CGRectMake(0, kScreenHeight, kScreenWidth, kScreenHeight)];
    hiddenView.backgroundColor = [UIColor colorWithRed:0.59f green:0.59f blue:0.59f alpha:.4f];
    hiddenView.alpha = 0;
    [self.view addSubview:hiddenView];
    UITapGestureRecognizer * shareTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shareCencle)];
    [hiddenView addGestureRecognizer:shareTap];

    if (kScreenWidth == 375) {
        self.shareView = [[[NSBundle mainBundle]loadNibNamed:@"ShareView" owner:self options:nil] objectAtIndex:1];
    } else if (kScreenWidth == 414) {
        self.shareView = [[[NSBundle mainBundle]loadNibNamed:@"ShareView" owner:self options:nil] objectAtIndex:2];
    }
    else {
        self.shareView = [[[NSBundle mainBundle]loadNibNamed:@"ShareView" owner:self options:nil] objectAtIndex:0];
    }
    self.shareView.alpha = 0;
    self.shareView.backgroundColor = [UIColor blackColor];
    self.shareView.frame=CGRectMake(0, kScreenHeight, kScreenWidth, self.shareView.height);
    [self.view addSubview:self.shareView];
    
    
    UITapGestureRecognizer * qqTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.qqView addGestureRecognizer:qqTap];
    UITapGestureRecognizer * qqZoneTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.qqZone addGestureRecognizer:qqZoneTap];
    UITapGestureRecognizer * wxTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.wxView addGestureRecognizer:wxTap];
    UITapGestureRecognizer * wxFrindTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.wxFriendView addGestureRecognizer:wxFrindTap];
    UITapGestureRecognizer * messageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.messageView addGestureRecognizer:messageTap];
    UITapGestureRecognizer * sinaTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(share:)];
    [self.shareView.sinaView addGestureRecognizer:sinaTap];
}
/**
 *  取消分享
 */
- (void)shareCencle
{
    [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
        CGRect rect = self.shareView.frame;
        rect.origin.y = kScreenHeight;
        self.shareView.frame = rect;
        self.shareView.alpha = 0;
        hiddenView.alpha = 0;
    } completion:^(BOOL finished) {
        CGRect rectHiddenView = hiddenView.frame;
        rectHiddenView.origin.y = kScreenHeight;
        hiddenView.frame = rectHiddenView;
    }];
    
}

#pragma - mark 显示分享界面
- (void)showShareView{
    [self.view bringSubviewToFront:hiddenView];
    [self.view bringSubviewToFront:self.shareView];
    
    CGRect rect = hiddenView.frame;
    rect.origin.y = 0;
    hiddenView.frame = rect;
    hiddenView.alpha = 1;
    
    [UIView animateWithDuration:0.3f delay:0.0f options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
        CGRect rectShareView = self.shareView.frame;
        rectShareView.origin.y = kScreenHeight - 185 - 64;
        self.shareView.frame = rectShareView;
        self.shareView.alpha = 1;
    } completion:^(BOOL finished) {
        MyNSLog("%f  %f  %F  %f ",self.shareView.frame.origin.x,self.shareView.frame.origin.y,self.shareView.frame.size.width,self.shareView.frame.size.height);
    }];
}

-(void)showCustomHudSingleLine:(NSString *)text
{
    UIView *customHud = [[UIView alloc] init];
    customHud.tag = 888;
    
    int width = text.length * 16 + 40;
    int height = 60;
    customHud.frame = CGRectMake((kScreenWidth - width)/2, (kScreenHeight - height)/2, width, height);
    customHud.layer.masksToBounds = YES;
    customHud.layer.cornerRadius = 8;
    customHud.backgroundColor = [UIColor blackColor];
    customHud.alpha = 0;
    
    UILabel *contenLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, width - 40, height - 40)];
    contenLabel.text = text;
    contenLabel.textColor = [UIColor whiteColor];
    contenLabel.font = [UIFont boldSystemFontOfSize:16];
    contenLabel.numberOfLines = 0;
    contenLabel.textAlignment = NSTextAlignmentCenter;
    [customHud addSubview:contenLabel];
    
    [[[UIApplication sharedApplication].delegate window] addSubview:customHud];


    
    [UIView animateWithDuration:0.3f animations:^{
        customHud.alpha = 0.8;
    } completion:^(BOOL finished) {
        
        [UIView animateWithDuration:1.5f animations:^{
            customHud.alpha = 0;
        } completion:^(BOOL finished) {
            customHud.hidden = YES;
            [customHud removeFromSuperview];
        }];

    }];
    
//    [self performSelector:@selector(hideCustomHud) withObject:nil afterDelay:1.0f];
}

-(void)hideCustomHud
{
    UIView *view = [[[UIApplication sharedApplication].delegate window] viewWithTag:888];
    [UIView animateWithDuration:0.3f animations:^{
        view.alpha = 0;
    } completion:^(BOOL finished) {
        view.hidden = YES;
        [view removeFromSuperview];
    }];
}

- (void)updateIsCollectionWithNid:(NSString *)nid andIsCollection:(NSInteger)isCollection{
    
}


#pragma mark - 新的加载中 -
- (void)baseViewAddLoadingView{
    self.LoadingView = [[UIView alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 40, kScreenHeight / 2 - 40, 80, 80)];
    self.LoadingView.backgroundColor = [UIColor blackColor];
    self.LoadingView.layer.masksToBounds = YES;
    self.LoadingView.layer.cornerRadius = 10;
    self.LoadingView.alpha = 0.6;
    [self.navigationController.view.superview addSubview:self.LoadingView];
//    [[[UIApplication sharedApplication].delegate window] addSubview:self.LoadingView];
    
    self.LoadingView.hidden = YES;
    UIImageView  *anHaoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(80 /2 - 49 / 5 * 4 / 2 + 2, 80 /2 - 37 / 5 * 4 / 2 , 49 / 5 * 4 , 37 / 5 * 4)];
    anHaoImageView.image = [UIImage imageNamed:@"安好小象"];
    [self.LoadingView addSubview:anHaoImageView];
    
    self.roundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 60, 60)];
    self.roundImageView.image = [UIImage imageNamed:@"加载椭圆"];
    [self.LoadingView addSubview:self.roundImageView];
    
    self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01f target:self selector:@selector(drawPathAnimation:) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop]addTimer:self.timer forMode:NSRunLoopCommonModes];

}


- (void)drawPathAnimation:(NSTimer *)timer
{
    self.timer = nil;
    [timer invalidate];
    [self startRotateAnimation];

}

- (void)startRotateAnimation
{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    animation.fromValue = @(0);
    animation.toValue = @(2 * M_PI);
    animation.duration = 0.7f;
    animation.repeatCount = INT_MAX;
    [self.roundImageView.layer addAnimation:animation forKey:@"keyFrameAnimation"];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
